package com.yzt.message.custom;

import android.os.Parcel;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yzt.zhuju.rongyun.IMMessageType;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

import io.rong.common.ParcelUtils;
import io.rong.imlib.MessageTag;
import io.rong.imlib.model.MessageContent;

@MessageTag(value = IMMessageType.TYPE_CHAT_ROOM_NOTICE_FENS_MSG ,flag = MessageTag.ISPERSISTED| MessageTag.ISCOUNTED)
public class RXChatRoomNoticeFensContent extends MessageContent {

    private String room_id;
    private String jump_url;
    private String text;

    @Override
    public byte[] encode() {
        JSONObject object =new JSONObject();
        object.put("room_id",room_id);
        object.put("jump_url",jump_url);
        object.put("text",text);

        return object.toString().getBytes(StandardCharsets.UTF_8);

    }

    public RXChatRoomNoticeFensContent() {
    }

    public RXChatRoomNoticeFensContent(byte[] data) {
        super(data);
        String jsonStr=null;
        try {
            jsonStr =new String(data, StandardCharsets.UTF_8);
            JSONObject object = JSON.parseObject(jsonStr);
            setRoom_id(object.getString("room_id"));
            setJump_url(object.getString("jump_url"));
            setText(object.getString("text"));

        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        ParcelUtils.writeToParcel(dest, room_id);
        ParcelUtils.writeToParcel(dest,jump_url);
        ParcelUtils.writeToParcel(dest,text);

    }

    public static final Creator<RXChatRoomNoticeFensContent> CREATOR = new Creator<RXChatRoomNoticeFensContent>() {

        @Override
        public RXChatRoomNoticeFensContent createFromParcel(Parcel source) {
            return new RXChatRoomNoticeFensContent(source);
        }

        @Override
        public RXChatRoomNoticeFensContent[] newArray(int size) {
            return new RXChatRoomNoticeFensContent[size];
        }
    };


    public RXChatRoomNoticeFensContent(Parcel parcel){

        room_id = ParcelUtils.readFromParcel(parcel);
        jump_url = ParcelUtils.readFromParcel(parcel);
        text = ParcelUtils.readFromParcel(parcel);
    }




    @Override
    public int describeContents() {
        return 0;
    }


    public String getRoom_id() {
        return room_id;
    }

    public void setRoom_id(String room_id) {
        this.room_id = room_id;
    }

    public String getJump_url() {
        return jump_url;
    }

    public void setJump_url(String jump_url) {
        this.jump_url = jump_url;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Override
    public String toString() {
        return "RXChatRoomNoticeFensContent{" +
                "room_id='" + room_id + '\'' +
                ", jump_url='" + jump_url + '\'' +
                ", text='" + text + '\'' +
                '}';
    }
}

